import {Directive, Input, Output, EventEmitter, HostListener} from "@angular/core";
import {ResponseMsgModel} from "../shared/model/response-msg-model";
import {CommonHelper} from "../../shared/helper/common-helper";
import {VerifyCommon} from "./verify-common";
@Directive({
    selector: "[retryPassValidator]"
})
export class VerifyRetryPassDirective extends VerifyCommon {
    @Input() retryPassValidator: string[];
    @Output() verifyResponse: EventEmitter<ResponseMsgModel> = new EventEmitter<ResponseMsgModel>();

    @HostListener("blur") onBlur() {
        let retryPass: string = CommonHelper.trim(this.retryPassValidator[0]),
            password: string = CommonHelper.trim(this.retryPassValidator[1]);

        if (!retryPass) {
            this.responseComponent(false, "确认密码不能为空");
        } else {
            let equalResult = retryPass === password;
            this.responseComponent(equalResult, equalResult ? "" : "两次密码不一致");
        }
    }

    getResponseEmitter(): EventEmitter<ResponseMsgModel> {
        return this.verifyResponse;
    }
}